<template>
	<view class="u-page">
		<u-navbar
			title="表单"
			@leftClick="navigateBack"
			safeAreaInsetTop
			fixed
			placeholder
		></u-navbar>
		<view class="u-demo-block">
			<text class="u-demo-block__title">基础使用</text>
			<view class="u-demo-block__content">
				<u--form
					labelPosition="left"
					:model="model1"
					ref="form1"
				>
					<u-form-item
						label="银行卡号"
						prop="userInfo.accountnumber"
						borderBottom
						ref="item1"
					>
						<u--input
							v-model="model1.userInfo.accountnumber"
							border="none"
							placeholder="请输入银行卡号"
						></u--input>
					</u-form-item>
					<u-form-item
						label="银行名称"
						prop="userInfo.bankname"
						borderBottom
						ref="item1"
					>
						<u--input
							v-model="model1.userInfo.bankname"
							border="none"
							placeholder="请输入银行名称"
						></u--input>
					</u-form-item>
					<u-form-item
						label="银行支行名称"
						prop="userInfo.bankforkname"
						borderBottom
						ref="item1"
					>
						<u--input
							v-model="model1.userInfo.bankforkname"
							border="none"
							placeholder="请输入银行支行名称"
						></u--input>
					</u-form-item>
				
				</u--form>
				<u-button
					type="primary"
					text="提交"
					customStyle="margin-top: 50px"
					@click="submit"
				></u-button>
				<u-button
					type="error"
					text="重置"
					customStyle="margin-top: 10px"
					@click="reset"
				></u-button>
			
			
			
		
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileList1: [],
				disabled1: false,
				tips: '',
				value: '',
				showCalendar: false,
				showBirthday: false,
				model1: {
					userInfo: {
						id:'',
						accountnumber:'',
						bankname:'',
						bankforkname:'',
						logininfoId:uni.getStorageSync('userid'),
						
					},
					radiovalue1: '苹果',
					checkboxValue1: [],
					intro: '',
					code: ''
				},
				showSex: false,
				birthday: Number(new Date()),
				
				
				
			}
		},
		onReady() {
			this.$refs.form1.setRules(this.rules)
		},
		methods: {
			afterRead(event) {
				this.fileList1.push({
					url: event.file,
					status: 'uploading',
					message: '上传中'
				})
			},
			groupChange(n) {
			},
			radioChange(n) {
			},
			navigateBack() {
				uni.navigateBack()
			},
			sexSelect(e) {
				this.model1.userInfo.sex = e.name
				this.$refs.form1.validateField('userInfo.sex')
			},
			change(e) {
				// console.log(e);
			},
			formatter(day) {
				const d = new Date()
				let month = d.getMonth() + 1
				const date = d.getDate()
				if (day.month == month && day.day == date + 3) {
					day.bottomInfo = '有优惠'
					day.dot = true
				}
				return day
			},
			calendarConfirm(e) {
				this.showCalendar = false
				this.model1.hotel = `${e[0]} / ${e[e.length - 1]}`
				this.$refs.form1.validateField('hotel')
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						uni.$u.toast('验证码已发送');
						this.$refs.uCode.start();
					}, 2000);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			calendarClose() {
				this.showCalendar = false
				this.$refs.form1.validateField('hotel')
			},
			birthdayClose() {
				this.showBirthday = false
				this.$refs.form1.validateField('userInfo.birthday')
			},
			birthdayConfirm(e) {
				this.showBirthday = false
				this.model1.userInfo.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
				this.$refs.form1.validateField('userInfo.birthday')
			},
			submit() {
				console.log(this.model1.userInfo);
				this.$api({
				  method: 'post',
				  url: '/system/userbankinfo/addBankinfo',
				  data: this.model1.userInfo
				}).then(res => {
				  this.bankCards = res.data;
				  uni.reLaunch({
				  	url:'/pages/user/user'
				  })
				}).catch(err => {
				  console.log(err);
				});
				 
				
			},
			reset() {
				const validateList = ['userInfo.name', 'userInfo.sex', 'radiovalue1', 'checkboxValue1', 'intro',
				'hotel', 'code', 'userInfo.birthday']
				this.$refs.form1.resetFields()
				this.$refs.form1.clearValidate()
				setTimeout(()=>{
					this.$refs.form1.clearValidate(validateList)
					
				},10)
			},
			hideKeyboard() {
				uni.hideKeyboard()
			}
		},
	}
</script>

<style lang="scss">

</style>
